﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using InsideDL.MISControl;
using InsideDL.MISService;
namespace InsideDL
{
    public partial class frmMerge : MISControl.frmMatrix 
    {
        protected InsideDL.MISService.EXLAPP exlAPP = null;
        public frmMerge()
        {
            InitializeComponent();
            this.controlList = new List<ucSelFileOrPath>
            {
                ucSaveCen,ucInside,ucTick,ucMerge
            };
            ucExecute1.ExecuteClick += new EventHandler(ucClickFacade);
            ucExecute_Exit.ExecuteClick += new EventHandler(ucClickFacade);
        }

        protected override void execute()
        {
            if (base.Vaildation().Equals(false))
            { return; }

            List<MergeXLS> mergeCollect = new List<MergeXLS>
            {
                new MergeXLS(){XLSName=ucSaveCen.Txt,CopyArea="E5:M41"
                    ,CopySheetName="央行等量率",TargetSheetName="合併-貼"
                    ,TargetRnage = "D5"
                }
                ,new MergeXLS(){XLSName=ucInside.Txt,CopyArea="E4:L36"
                    ,CopySheetName="53存.放款量率",TargetSheetName="合併-貼"
                    ,TargetRnage = "D42"
                }
                ,new MergeXLS(){XLSName=ucTick.Txt,CopyArea="F4:N79"
                    ,CopySheetName="債票券量率",TargetSheetName="合併-貼"
                    ,TargetRnage = "D75"
                }
            };

            //信用卡用原版-{0}NIM合併表.xls
            string flName = string.Format("信用卡用原版-{0}NIM合併表"
                , Utility.GetTWYM());
            
            createNewFile(flName, System.IO.Path.GetDirectoryName(ucMerge.Txt)
                , ucMerge.Txt);
            exlAPP = new InsideDL.MISService.EXLAPP();
            exlAPP.OpenFile(newFile);
            exlAPP.SetRangeValue("合併-貼", "B3"
                ,string.Format("'{0}", Utility.GetTWYM())
                );
            exlAPP.SetRangeValue("合併表", "A1",
                string.Format("'{0}", Utility.GetCurrentDay()  ) );


            foreach(MergeXLS mg in mergeCollect)
            {
                exlAPP.OpenFile(mg.XLSName);
                exlAPP.CopyPaste(mg.CopySheetName, mg.CopyArea
                    , mg.TargetSheetName, mg.TargetRnage);

            }
            exlAPP.SaveCloseXLS();
            showMessage(this.Text, "完成！");
        }
    }
}
